import javax.media.opengl.GL;
import javax.media.opengl.GL2;
import javax.media.opengl.GLAutoDrawable;


public class Circle extends PhysicsObject {
	/** The number of triangles used to approximate this circle. **/
	private static final int RESOLUTION = 64;

	/** A table of coordinates only calculated once **/
	private static final float[][] VERTS = new float[RESOLUTION][2];
	static {
		double theta = 0f;
		for (int i = 0; i < RESOLUTION; i++) {
			theta = (i * 2 * Math.PI) / RESOLUTION;
			VERTS[i] = new float[2];
			VERTS[i][0] = (float)Math.sin(theta);
			VERTS[i][1] = (float)Math.cos(theta);
		}
	}
	
	float radius;
	float red;
	float green;
	float blue;

	public Circle(float radius) {
		this(radius, (float)Math.random(), (float)Math.random(), (float)Math.random());
	}
	
	public Circle(float radius, float red, float green, float blue) {
		inverseMomentOfInertia = 1 / (float)(Math.PI * Math.pow(radius, 4) / 4);
		this.radius = radius;
		this.red = red;
		this.green = green;
		this.blue = blue;
		renderable = new Renderable();
	}
	
	private class Renderable extends SceneGraphNode {
		public Renderable() {
			scale = radius;
			physics = Circle.this;
		}
	
		public void renderGeometry(GLAutoDrawable drawable) {
			GL2 gl = drawable.getGL().getGL2();
			gl.glBegin(GL.GL_TRIANGLE_FAN);
			//Start at center
			gl.glColor3f(1, 0, 0);
			gl.glVertex2f(0,0);
			gl.glColor3f(0, 1, 0);
			//go to each vertex
			for (float[] coord : VERTS) {
				gl.glVertex2f(coord[0], coord[1]);
			}
			gl.glVertex2f(0, 1);
			gl.glEnd();
		}
	}
}
